package com.yw.android.common;

import android.os.Environment;

import com.yw.android.common.utils.SystemUtils;
import com.yw.android.common.utils.TextUtils;
import com.yw.android.sys.common.BuildConfig;

import java.io.File;

/**
 * 指定当前API的发布说明
 *
 * @author yuanwei
 */
public class Release {
    /**
     * 标签
     */
    private static final String TAG = "Release";
    /**
     * 是否为debug
     */
    public static boolean DEBUG = BuildConfig.DEBUG;


    public static void initDebug() {
        try {
            String efuse = (String) SystemUtils.getProperty("ro.boot.efuse", "");//熔丝
            String userdebug = (String) SystemUtils.getProperty("ro.build.fingerprint", "");//userdebug版本
            //未熔丝 userdebug版本输出日志信息
            if (DEBUG || TextUtils.containsIgnoreCase(userdebug, "userdebug")
                    || isDebugFileExist("yw.debug") || !TextUtils.equalsIgnoreCase(efuse, "yes"))
                DEBUG = true;
        } catch (Throwable t) {
            android.util.Log.e(TAG, "initDebug Throwable : " + t);
        }
    }

    private static boolean isDebugFileExist(String fileName) {
        try {
            String sdcardPath = Environment.getExternalStorageDirectory().getAbsolutePath();
            File file = new File(sdcardPath + File.separator + fileName);
            if (file.exists()) {
                return true;
            }
        } catch (Throwable t) {
            android.util.Log.e(TAG, "isDebugFileExist Throwable : " + t);
        }
        return false;
    }

}
